package com.weigee.ktv.view.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CompoundButton
import com.linde.library.util.DisplayUtil
import com.linde.library.util.ToastUtil
import com.weigee.ktv.R
import com.weigee.ktv.view.activity.PayingActivity
import com.weigee.ktv.view.dialog.PayingReplaceLocationDialog
import kotlinx.android.synthetic.main.frag_paying.*
import kotlinx.android.synthetic.main.include_status_bar_height.*
import kotlinx.android.synthetic.main.include_title_bar.*

/**
 * Created by linde on 2017/6/12.
 * LinDe
 */
class PayingFragment : BaseFragment()
{
    // 允许提交支付
    var isEnabledPayingCommit: Boolean = false
        set(value)
        {
            field = value
            tv_paying_commit?.isEnabled = value
        }
    // 钱包支付
    var isPayingByWallet = false
        set(value)
        {
            field = value
            paying_wallet?.isChecked = value
            if (value)
            {
                isPayingByWeChat = false
                isPayingByAli = false
            }
        }
    // 微信支付
    var isPayingByWeChat = false
        set(value)
        {
            field = value
            paying_wechat?.isChecked = value
            if (value)
            {
                isPayingByWallet = false
                isPayingByAli = false
            }
        }
    // 支付宝支付
    var isPayingByAli = false
        set(value)
        {
            field = value
            paying_ali?.isChecked = value
            if (value)
            {
                isPayingByWallet = false
                isPayingByWeChat = false
            }
        }
    // 更换门面
    var replaceLocationDialog: PayingReplaceLocationDialog? = null

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View?
    {
        // 必须是由PayingActivity启动该Fragment，确保应用内只有一个支付Activity（单例）
        activity as PayingActivity
        return inflater?.inflate(R.layout.frag_paying, container, false)
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?)
    {
        super.onViewCreated(view, savedInstanceState)
        DisplayUtil.setStatusBarHeight(linear_status_bar_height)
        // 左上角返回键
        my_title_bar?.leftIconClickBack = activity
        // 标题
        my_title_bar?.title = "付款"
        // 切换地点（商家）
        tv_replace_location?.setOnClickListener {
            replaceLocationDialog?.dismiss()
            replaceLocationDialog = PayingReplaceLocationDialog()
            replaceLocationDialog?.show(childFragmentManager, javaClass.name)
        }
        // 提交按钮
        tv_paying_commit?.setOnClickListener { ToastUtil.show(tv_paying_commit, "确认支付") }
        // 支付方式选择
        paying_wallet?.onCheckChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked -> isPayingByWallet = isChecked }
        paying_wechat?.onCheckChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked -> isPayingByWeChat = isChecked }
        paying_ali?.onCheckChangeListener = CompoundButton.OnCheckedChangeListener { _, isChecked -> isPayingByAli = isChecked }
    }

    override fun onResume()
    {
        super.onResume()
    }
}